//
//  TestYogaVC.swift
//  CooperSwift_Example
//
//  Created by 计海峰 on 2021/6/3.
//  Copyright © 2021 CocoaPods. All rights reserved.
//

import UIKit
import CooperSwift
import YogaKit

class TestYogaVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        bgColor(.white)
        
        // 1
        let contentView = UIView()
        contentView.backgroundColor = .lightGray
        // 2
        contentView.configureLayout { (layout) in
          // 3
          layout.isEnabled = true
          // 4
          layout.flexDirection = .row
          layout.width = YGValue(Screen.width - 20)
          layout.height = 80
            layout.marginTop = YGValue(Screen.statusBarHeight + Screen.navBarHeight + 10)
          layout.marginLeft = 10
        }
        
        let child1 = UIView()
        child1.backgroundColor = .red
        child1.configureLayout{ (layout)  in
          layout.isEnabled = true
          layout.width = 80
            layout.padding = 10
            layout.marginRight = 10
        }
        contentView.addSubview(child1)
        
        
        let child2 = UIView()
        child2.backgroundColor = .blue
        child2.configureLayout{ (layout)  in
          layout.isEnabled = true
          layout.width = 80
          layout.flexGrow = 1
            layout.padding = 10
            layout.marginRight = 10
            layout.height = 20
            layout.alignSelf = .center
        }
        contentView.addSubview(child2)
        
        
        view.configureLayout { layout in
            layout.isEnabled = true
              layout.width = YGValue(self.view.bounds.size.width)
              layout.height = YGValue(self.view.bounds.size.height)
              layout.alignItems = .center
            layout.justifyContent = .center
        }
        view.addSubview(contentView)
        // 5
        view.yoga.applyLayout(preservingOrigin: true)
        
        
        
        // Do any additional setup after loading the view.
    }
    
 
    
    override func viewWillTransition(
      to size: CGSize,
      with coordinator: UIViewControllerTransitionCoordinator) {
      super.viewWillTransition(to: size, with: coordinator)
      // 1
      view.configureLayout{ (layout) in
        layout.width = YGValue(size.width)
        layout.height = YGValue(size.height)
      }
      // 2
      view.yoga.applyLayout(preservingOrigin: true)
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
